﻿function refreshParent() {
    if (window.top != window) {
        window.top.jQuery.refresh();
    }
    window.opener = null;
    window.open("", "_self");
    window.close();
}

var addFrame = null;

function closeFrame() {
    if (addFrame != null)
        dhtmlwindow.close(addFrame);
}

$(document).ready(function() {
    $(document).bind("click", function(evt) {
    //$(".UpdateButton").click(function(evt) {
        var target = evt.target;
        //var isAddButton = $(target).hasClass("addData");
        var isEdtField = $(target).hasClass("FieldText") && ($(target).filter("input:[IsForeignKey='true'][EDTType][EDTType!='']").length > 0);
        var isFrame = $(target).parents("div.dhtmlwindow").length > 0; //(target.parentNode != null) && $(target.parentNode).hasClass("dhtmlwindow"); //
        //if ((!isEdtField) && (!isFrame) && (!isAddButton )) {
        if ((!isEdtField) && (!isFrame) ) {        
            closeFrame();
        }        
    });
    if ($.TableFieldValidate != null)
    {
        $.TableFieldValidate.Vaidate("FieldText", "UpdateButton");
    }
    $("input:[IsForeignKey='true'][EDTType][EDTType!='']").focus(function() {
        addFrame = dhtmlwindow.open('iframebox_add', 'iframe', '/Public/EDTLookUpForm.aspx?id=' + $(this).attr("id") + '&edttype=' + $(this).attr("EDTType"), '选择主键值', 'width=480px,height=300px,center=1,top=100px,resize=1,scrolling=1');
        var position = $(this).position();
        $(addFrame).css("left", position.left + "px").css("top",$(this).outerHeight()+position.top+"px");
    })
    $("input:[IsForeignKey='true'][EDTType][EDTType!='']").keydown(function() { return true; });
});